/****************************************************
          File Name:wine.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Fri, Jan 09, 2015  2:55:57 PM
*****************************************************/

#ifndef WINE_H_
#define WINE_H_

#include<string>
#include<iostream>

using std::string;
using std::cout;
using std::cin;
using std::endl;

class Pair
{
    private:
        int *wine_year;
        int *wine_bottles;
    public:
        Pair(int a, int b);
        Pair(const int *a, const int *b);
		~Pair() {};

        int* & GetBot();                        // return (int *) 's reference
        void set(int year, int bottles, int i);
        void  put(int i);
};

Pair::Pair(int a, int b)
{
    wine_year = new int(a);
    wine_bottles = new int(b);
}

Pair::Pair(const int *a, const int *b)
{
    wine_year = new int[sizeof(a) / sizeof(int)];
    wine_bottles = new int[sizeof(b) / sizeof(int)];

    for(int i=0; a[i] != '\0'; i++)
        wine_year[i] = a[i];

    for(int i=0; b[i] != '\0'; i++)
        wine_bottles[i] = b[i];
}

int* & Pair::GetBot()
{
    return wine_bottles;
}

void Pair::set(int year, int bottles, int i)
{
    wine_year[i] = year;
    wine_bottles[i] = bottles;
}

void Pair::put(int i)
{
    cout << "\t" << wine_year[i] << "\t" << wine_bottles[i] << endl;;
}

class Wine
{
    private:
        string wine_label;
        int number_of_year;
        Pair info;
    public:
        Wine(const char *l, int y, const int yr[], const int bot[]);
        Wine(const char *l, int y);

        void GetBottles();
        string & Label() { return wine_label; }
        void Show();
        int sum();
};

Wine::Wine(const char *l, int y, const int yr[], const int bot[]) 
: wine_label(l), number_of_year(y), info(yr, bot) {}

Wine::Wine(const char *l, int y): wine_label(l), number_of_year(y), info(y,y) {}

void Wine::GetBottles()
{
	int i;
    cout << "Enter " << wine_label << " data for " << number_of_year << " years:\n";
    for(i=0; i<number_of_year; i++)
    {
        int year, number;
        cout << "Enter year: ";
        (cin >> year).get();
        cout << "Enter bottles for that year: ";
        (cin >> number).get();

        info.set(year, number, i);
    }
}


void Wine::Show()
{
    cout << "Wine: " << wine_label << endl;
    cout << "\tYear\tBottles" << endl;

    for(int i=0; i<number_of_year; i++)
        info.put(i); 
}

int Wine::sum()
{
	int tmp = 0;
	for(int i=0; i<number_of_year; i++)
		tmp += info.GetBot()[i];
	
	return tmp;
}

#endif
